package com.haifeng.CRUD.dao.impl;

import com.haifeng.CRUD.dao.UserDao;
import com.haifeng.CRUD.domain.User;
import com.haifeng.CRUD.utils.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public User findUserByNameAndPassword(User loginUser) {
       try {
           String sql="Select * from user where username=?and password=?";
           User user = template.queryForObject(sql, new BeanPropertyRowMapper<User>(User.class),
                   loginUser.getUsername(), loginUser.getPassword());
           return user;
       }catch (Exception e){
//           e.printStackTrace();
           return null;
       }
    }
}
